package com.shensi.api.pay.client;


import com.alibaba.fastjson.JSONObject;
import com.shensi.api.pay.param.request.AppUserInfoRequest;
import com.shensi.api.pay.param.vo.AppUserInfoVO;
import com.shensi.api.pay.pojo.vo.UserInfoVo;
import com.shensi.common.core.constant.CloudConstant;
import com.shensi.api.pay.param.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"app用户登录"})
@FeignClient(name = CloudConstant.PAY_SERVER, path = "/api/v1/mixc/goods/coupon")
public interface AppUserInfoClient {


    //获取支付宝用户信息
    @ResponseBody
    @RequestMapping(value = "/getAliUserInfo")
    public String getAliUserInfo(String authCode);

    //获取支付宝用户信息
    @ResponseBody
    @RequestMapping(value = "/getAliUserId")
    public String getAliUserId(String authCode);

    //支付宝小程序用户手机号解密 encryptedData
    @ResponseBody
    @RequestMapping(value = "/alipayEncryptUserPhone", method = RequestMethod.POST, consumes = "application/json")
    public String alipayEncryptUserPhone(@RequestBody JSONObject jsonObject);


    /*
     * 微信小程序根据code获取用户openId和sessionKey
     * @param code
     * @param stationId
     * @return
     */
    @ResponseBody
    @GetMapping(value = "/getSessionKeyAndOpenID")
    @ApiOperation(value = "微信小程序根据code获取用户openId和sessionKey", httpMethod = "GET", notes = "微信小程序根据code获取用户openId和sessionKey")
    public String getSessionKeyAndOpenID(@ApiParam(value = "code码", required = true) @RequestParam("code") String code,
                                         @ApiParam(value = "油企ID") @RequestParam("enterpriseId") Integer enterpriseId,
                                         @ApiParam(value = "站点ID") @RequestParam("stationId") Integer stationId,
                                         @ApiParam(value = "接口版本") @RequestParam("version") Integer version);

    /***
     * 登录入口
     * @param code
     * @return
     */
    @ResponseBody
    @GetMapping(value = "/loginGetPhone")
    @ApiOperation(value = "根据code，获取手机号", httpMethod = "GET", notes = "微信小程序根据code获取用户openId和sessionKey")
    @Transactional
    public String getPhoneWithLogin(
            @ApiParam(value = "code码", required = true) @RequestParam("code") String code,
            @ApiParam(value = "站点ID") @RequestParam("stationId") Integer stationId,
            @ApiParam(value = "解密码", required = true) @RequestParam("encryptedData") String encryptedData,
            @ApiParam(value = "偏移量", required = true) @RequestParam("iv") String iv,
            @ApiParam(value = "昵称") @RequestParam("blogNickName") String blogNickName,
            @ApiParam(value = "性别") @RequestParam("sexFlag") String sexFlag,
            @ApiParam(value = "头像") @RequestParam("blogProfilePhoto") String blogProfilePhoto,
            @ApiParam(value = "接口版本") @RequestParam("version") Integer version
    );

    @PostMapping("/increaseShareCount")
    @ApiOperation(value = "增加分享次数", notes = "根据用户ID增加分享次数")
    @ResponseBody
    public void increaseShareCount(Long userId);

    @GetMapping("/getShareCount")
    @ApiOperation(value = "获取分享次数", notes = "根据用户ID获取分享次数")
    @ResponseBody
    public Integer getShareCountByUserId(Long userId);


    @ResponseBody
    @RequestMapping(value = "/getSessionKeyAndOpenIDByAppType")
    public String getSessionKeyAndOpenIDByAppType(@RequestParam("code") String code, @RequestParam("appType") Integer appType);


    @ResponseBody
    @RequestMapping(value = "/getPaySessionKeyAndOpenID")
    public String getPaySessionKeyAndOpenID(@RequestParam("code") String code, @ApiParam(value = "油企ID") @RequestParam("enterpriseId") Integer enterpriseId);

    /*
     * 解密 encryptedData
     * @param sessionKey
     * @param encryptedData
     * @param iv
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/decryptEncryptedData", method = RequestMethod.POST, consumes = "application/json")
    @ApiOperation(value = "解密获取手机号", httpMethod = "POST", notes = "解密获取手机号")
    public String decryptEncryptedData(@RequestBody JSONObject jsonObject);

    /*
     * JS-SDK使用权限签名算法
     * @param noncestr  随机字符串
     * @param timestamp 时间戳
     * @param url   页面访问路径
     * @param stationId 油站ID
     * @return
     */
    @RequestMapping(value = "/getSignature", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "JS-SDK使用权限签名算法", httpMethod = "GET", notes = "JS-SDK使用权限签名算法")
    public String getSignature(@ApiParam(value = "随机字符串", required = true) @RequestParam("noncestr") String noncestr,
                               @ApiParam(value = "时间戳", required = true) @RequestParam("timestamp") String timestamp,
                               @ApiParam(value = "页面访问路径", required = true) @RequestParam("url") String url,
                               @ApiParam(value = "油企ID", required = true) @RequestParam("enterpriseId") Integer enterpriseId);

    /*
     * 微信卡券签名
     * @param noncestr
     * @param timestamp
     * @param enterpriseId
     * @return
     */
    @RequestMapping(value = "/getCardSignature", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "微信卡券签名", httpMethod = "GET", notes = "微信卡券签名")
    public String getCardSignature(@ApiParam(value = "随机字符串", required = true) @RequestParam("noncestr") String noncestr,
                                   @ApiParam(value = "时间戳", required = true) @RequestParam("timestamp") String timestamp,
                                   @ApiParam(value = "卡券ID", required = true) @RequestParam("cardId") String cardId,
                                   @ApiParam(value = "油企ID", required = true) @RequestParam("enterpriseId") Integer enterpriseId);

    /*
     * 判断使用小程序支付的用户是否关注公众号
     * @param unionId
     * @param stationId
     * @return
     */
    @RequestMapping(value = "/whetherFollowGzh", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "判断使用小程序支付的用户是否关注公众号", httpMethod = "GET", notes = "判断使用小程序支付的用户是否关注公众号")
    public String whetherFollowGzh(@ApiParam(value = "用户unionId", required = true) @RequestParam("unionId") String unionId,
                                   @ApiParam(value = "油企ID", required = true) @RequestParam("enterpriseId") Integer enterpriseId);

    /*
     * 获取公众号授权后的信息
     * @param code
     * @param stationId
     * @return
     */
    @RequestMapping(value = "/getGzhAuthorizeInfo", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取公众号授权后的信息", httpMethod = "GET", notes = "获取公众号授权后的信息")
    public String getGzhAuthorizeInfo(@ApiParam(value = "code码", required = true) @RequestParam("code") String code,
                                      @ApiParam(value = "油企ID", required = true) @RequestParam("enterpriseId") Integer enterpriseId);

    //获取油站公众号ID
    @RequestMapping(value = "/getStat", method = RequestMethod.GET)
    @ResponseBody
    public String getStationGzh(Integer enterpriseId);

    //获取油站公众号ID
    @RequestMapping(value = "/getStationGzhAppId", method = RequestMethod.GET)
    @ResponseBody
    public String getStationGzhAppId(Integer enterpriseId);


    /*
     * 获取公众号信息
     * @param openId
     * @param stationId
     * @return
     */
    @RequestMapping(value = "/getGzhUserInfo", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取公众号用户信息", httpMethod = "GET", notes = "获取公众号用户信息")
    public String getGzhUserInfo(@ApiParam(value = "公众号openId", required = true) @RequestParam("openId") String openId,
                                 @ApiParam(value = "油企ID", required = true) @RequestParam("enterpriseId") Integer enterpriseId);

    @GetMapping("/getToken")
    @ResponseBody
    public String getAccessToken(@RequestParam("appId") String appId, @RequestParam("appSecret") String appSecret);


    /*
     * 添加用户信息
     * @param request
     * @return
     */
    @RequestMapping(value = "/addAppUserInfo", method = RequestMethod.POST)
    @ResponseBody
    @Transactional
    public String addAppUserInfo(@RequestBody AppUserInfoRequest request);


    @ResponseBody
    @RequestMapping(value = "/getPaySessionKeyAndID")
    public String getPaySessionKeyAndID(@ApiParam(value = "油企ID") @RequestParam("enterpriseId") Integer enterpriseId);

    @ResponseBody
    @GetMapping("/getOrCreateUserInfo")
    public ResultData<UserInfoVo> getOrCreateUserInfo(@RequestParam("openId") String openId,
                                                      @RequestParam("nickName") String nickName,
                                                      @RequestParam("enterpriseId") Integer enterpriseId);


    @GetMapping("/inspectRegisteredUser")
    @ApiOperation(value = "检查用户是否注册成功")
    @ResponseBody
    public ResultData<AppUserInfoVO> inspectRegisteredUser(@ApiParam(value = "油企ID", required = true) @RequestParam("enterpriseId") Integer enterpriseId,
                                                           @ApiParam(value = "用户手机号", required = true) @RequestParam("mobilePhone") String mobilePhone);

}
